﻿using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraCharts;
using DevExpress.XtraGauges.Win.Gauges.State;
using Zero.POCO.Views;

namespace DevExpress.MailClient.Win.Controls {
    public partial class WidgetAge : UserControl {
        Timer updateTimer = new Timer();
        static Color positiveColor = Color.FromArgb(70, 158, 165);
        static Color negativeColor = Color.FromArgb(165, 70, 113);
        public WidgetAge()
        {
            InitializeComponent();
            updateTimer.Interval = 1000;
            updateTimer.Tick += OnTimerTick;
            updateTimer.Start();
            OnTimerTick(this, EventArgs.Empty);
        }
      
        int index = 0;
       // StockData previousData;
        void OnTimerTick(object sender, EventArgs e) {
          /*  if(IsDisposed) { updateTimer.Stop(); return; }
            StockData data = StockDataCreator.GetData(index);
            if(index > 0) {
                decimal d = data.ClosePrice - previousData.ClosePrice;
                decimal dq = (d * 100) / data.ClosePrice;
                labelControl5.Text = Math.Round( d, 2, MidpointRounding.ToEven).ToString().TrimEnd('0');
                stateIndicatorComponent1.StateIndex =  previousData.ClosePrice - data.ClosePrice < 0 ? 0 : 1;
                if(stateIndicatorComponent1.StateIndex == 0) {
                    labelControl5.ForeColor = positiveColor;
                    labelControl2.Text = data.ClosePrice.ToString().TrimEnd('0') + "<br><color=70,158,165>" + Math.Round(dq, 2, MidpointRounding.ToEven).ToString().TrimEnd('0') + '%';
                }
                else {
                    labelControl5.ForeColor = negativeColor;
                    labelControl2.Text = data.ClosePrice.ToString().TrimEnd('0') + "<br><color=165,70,113>" + Math.Round(dq, 2, MidpointRounding.ToEven).ToString().TrimEnd('0') + '%';
                }
            }
            previousData = data;
            index++;*/
        }
        public void UpdateStat(ProfilPenetrationView profilPenetrationView)
        {
            //ccSexe.DataSource = ProfilPenetrationView.ProfilPenetrationSupport.First().StatistiqueSexe;
            ccAge.Series.Clear();
            var series1 = new Series("Age", ViewType.Pie);

            series1.Points.Add(new SeriesPoint("Moins 12", profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatitiqueAge.moins12));
            series1.Points.Add(new SeriesPoint("12-25", profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatitiqueAge.Entre12Et25));
            series1.Points.Add(new SeriesPoint("25-55", profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatitiqueAge.Entre25Et55));
            series1.Points.Add(new SeriesPoint("plus de 55", profilPenetrationView.ProfilPrincipale.ProfilPrincipale.StatitiqueAge.Plusde55));
            ccAge.Series.Add(series1);

            // Format the the series labels.
            series1.Label.TextPattern = "{A}: {VP:p0}";
        }
        private void OnCustomDrawElement(object sender, DevExpress.XtraGauges.Core.Primitive.CustomDrawElementEventArgs e) {
            e.Handled = true;
            StateIndicatorComponent indicator = sender as StateIndicatorComponent;
            Point p1 = Point.Empty;
            Point p2 = Point.Empty;
            Point p3 = Point.Empty;
            int height = (int)(e.Info.BoundBox.Width * Math.Sqrt(3) / 2);
            p1.X = (int)(e.Info.BoundBox.Width / 2);
            p2.X = (int)e.Info.BoundBox.Left;
            p3.X = (int)e.Info.BoundBox.Right;
            int y = (int)((e.Info.BoundBox.Height - height) / 2);
            Color stateColor = Color.Empty;
            if(indicator.StateIndex == 0) {
                p1.Y = y;
                p2.Y = p3.Y = y +height;
                stateColor = positiveColor;
            }
            else {
                p1.Y = y + height;
                p2.Y = p3.Y = y;
                stateColor = negativeColor;
            }
            e.Context.Graphics.FillPolygon(new SolidBrush(stateColor), new Point[] { p1, p2, p3 });
        }

        private void tableLayoutPanel2_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}
